package it.univaq.di.helpdesk.common.utils;

import java.util.HashMap;
import java.util.Map;

public class MimeTypeImgHelper {
	private Map<String, String> data;
	private final String BASE_PATH = "/layout/images/form/";
	
	private static MimeTypeImgHelper instance = null;
	
	private MimeTypeImgHelper() {
		data = new HashMap<String, String>();
		
		data.put("application/pdf", "iconPdf.png");
		data.put("application/msword", "iconWord.png");
		data.put("text/plain", "iconTXT.png");
		data.put("application/zip", "iconZip-Rar.png");
		data.put("application/x-gzip", "iconZip-Rar.png");
		data.put("application/x-tar", "iconZip-Rar.png");
		data.put("application/rar", "iconZip-Rar.png");
		data.put("application/x-rar-compressed", "iconZip-Rar.png");
		data.put("image/gif", "iconImages.png");
		data.put("image/png", "iconImages.png");
		data.put("image/jpeg", "iconImages.png");
		data.put("image/bmp", "iconImages.png");
		data.put("fallback", "iconOther.png");
	}
	
	public static synchronized MimeTypeImgHelper getInstance() {
		if (instance == null) {
			instance =  new MimeTypeImgHelper();
		}
		
		return instance;
	}
	
	public String getIconPath(String mime) {
		String path = data.get(mime);
		
		if (path == null) {
			path = data.get("fallback");
		}
		
		return BASE_PATH + path;
	}
}
